package com.banciyuan.bcywebview.biz.detail.goods;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.fragment.BaseFragment;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import de.greenrobot.daoexample.model.Multi;


/**
 * Created by squall on 2016/10/27.
 */

public class GoodsPicFragment extends BaseFragment {

    private ImageView imageView;
    private List<Multi> mlist = new ArrayList<>();
    private int index;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View viewroot = inflater.inflate(R.layout.goods_detail_img, null);
        mlist = (List<Multi>) getArguments().getSerializable("images");
        index = getArguments().getInt("index");
        imageView = (ImageView) viewroot.findViewById(R.id.item_loading_img);
        ImageLoader.getInstance().displayImage(mlist.get(index).getPath(), imageView, ImageOptions.optionsDetail);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<String> slist = new ArrayList<>();
                for (Multi m : mlist) {
                    slist.add(m.getPath());
                }
                Intent intent = new Intent(getActivity(), GoodsBigImageActivity.class);
                intent.putExtra("imageUrls", (Serializable) slist);
                intent.putExtra("position", index);
                startActivity(intent);
            }
        });
        return viewroot;
    }
}
